new Vue({
    el: '#app',
    data() {
        return {
            loading: false,
            Newpassword: '',
            Newpasswordtwo:'',
            form: {}
        }
    },
    mounted() {
        this.getUserinfo($.cookie("use"))
    },
    methods: {
        Change() {
            if (this.Newpassword.trim() == '') {
                this.$message({
                    message: '请输入您要修改的新密码',
                    type: 'warning'
                });
                return
            }
            let reg = /^(?=.*[a-z])(?=.*\d)[^]{6,16}$/;
            if (!reg.test(this.Newpassword)) {
                this.$message({
                    message: '您设置的密码长度应为6-16位,且为字母跟数字的组合',
                    type: 'error'
                });
                return
            }
            if (this.Newpasswordtwo.trim() == '') {
                this.$message({
                    message: '请再次输入新密码',
                    type: 'warning'
                });
                return
            }
            if (this.Newpassword == this.form.Pass_Ward) {
                this.$message({
                    message: '新密码不能与旧密码重复',
                    type: 'error'
                });
                return
            }
            if (this.Newpassword != this.Newpasswordtwo) {
                this.$message({
                    message: '两次输入的密码不一致',
                    type: 'error'
                });
                return
            }
            this.loading = true
            this.form.Pass_Ward = this.Newpassword
            const this_ = this
            $.ajax({
                type: 'POST',
                url: `${DomainName}/getEditAction?token=` + $.cookie("token"),
                data: {
                    Data: JSON.stringify(
                        {
                            Modify: { 'system_user_info': [this_.form] },
                        }
                    )
                },
                complete: function (XMLHttpRequest) {
                    this_.loading = true
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                success: function (Result) {
                    console.log(Result)
                    if (Result.Status == 'success') {
                        this_.$message({
                            message: '修改成功!即将返回首页重新登录',
                            type: 'success'
                        });
                        window.sessionStorage.clear()
                        window.localStorage.clear()
                        $.removeCookie('token', { path: '/' });
                        window.parent.document.location.href = "../../../login.html"
                    } else {
                        this_.$message({
                            message: '修改失败!请稍后重试',
                            type: 'error'
                        });
                    }
                },
                dataType: "json"
            });
        },
        getUserinfo(Primary_Key) {
            const this_ = this
            $.ajax({
                type: 'POST',
                url: `${DomainName}/getInquiryIDOriginal?token=` + $.cookie('token'),
                data: {
                    Primary_Key_Name: 'User_Number', //主键名
                    Primary_Key, //主键值
                    Data: 'system_user_info',
                },
                complete: function (XMLHttpRequest) {
                    if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
                        window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
                    }
                },
                success: function (Result) {
                    console.log(Result)
                    this_.form = Result[0]
                },
                dataType: "json"
            });
        }
    }
})